package com.example.test_demo.test;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: Demo
 * @description: s
 * @author: yanghua   DAYWEEKEND
 * @create: 2021-05-07 11:53
 **/
public class Apple {
    public static void main(String[] args) {
        float f=1.3f;
        double b =1.3;

        String year = "2016";
        Calendar c = Calendar.getInstance();
        c.set(Integer.parseInt(year), 0, 1);
        Calendar c2 = Calendar.getInstance();
        c2.set(Integer.parseInt(year) + 1, 0, 1);
        int count = 0;
        while (c.compareTo(c2) < 0) {
            if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                System.out.println(new SimpleDateFormat("yyyyMMdd").format(c.getTime().clone()) );
                count++;
            }
            // 日期+1
            c.add(Calendar.DATE, 1);
        }


//        Date bdate = new Date();
//        Calendar cal = Calendar.getInstance();
//        cal.setTime(bdate);
//        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
//        {
//            System.out.println("ok");
//        } else
//            System.out.println("no");










        //System.out.println(new BigDecimal("1305.01").divide(new BigDecimal(19), Integer.valueOf(3), BigDecimal.ROUND_HALF_DOWN));
        //jsonStrToJava();
        //System.out.println(new BigDecimal("20210812").add(new BigDecimal(1)));
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
//        String date="20210530";
//
//        System.out.println(addDateOneDay(date,formatter));
//        String str="Aug/01/2021".replace("/"," ");
//
//        String date = "Wed Aug 01 00:00:00 CST 2012";
//
//        //SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
//        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy", Locale.US);
//        try {
//            Date d=sdf.parse(str);
//            sdf=new SimpleDateFormat("yyyyMMdd");
//
//            System.out.println(sdf.format(d));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        String str ="451".toUpperCase();
//
//
//        System.out.println((str + " ").contains("@") ?
//                (str + " ").split("@")[1].trim() :
//                str.toUpperCase());
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
//        DateFormat df = new SimpleDateFormat("yyyyMMdd");
//        String str ="20210611";
//
//        try {
//            System.out.println(simpleDateFormat.format(df.parse(str)));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
        //System.out.println(BigDecimal.valueOf(27.673).multiply(BigDecimal.valueOf(720000)).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
//        String str = "1111";
//        System.out.println(str.contains(" "));
//
//        if(str.indexOf(" ")!=-1){
//            System.out.println("存在非法字符!");
//        }else{
//            System.out.println("字符串合法");
//        }
//
//        System.out.println(str.matches("[0-9]+"));

//        List<String> strings = new ArrayList<>();
//        strings.add("111");
//        strings.add("aaa");
//        strings.add("a232");
//        List<String> nl = strings.stream().filter(s -> s.matches("[0-9]+")).collect(Collectors.toList());
//        nl.stream().forEach(n->{
//            System.out.println(n);
//        });
        //System.out.println(new BigDecimal("0.00000"));


    }

    public static String addDateOneDay(String date,SimpleDateFormat formatter) {
        if (null == date) {
            return date;
        }
        try {
            Date oldDate = formatter.parse(date);
            Calendar c = Calendar.getInstance();
            c.setTime(oldDate); // 设置当前日期
            c.add(Calendar.DATE, -1); // 日期加1天
            Date newDate = c.getTime();
            return formatter.format(newDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;

    }
    public static void jsonStrToJava(){
        //定义两种不同格式的字符串
        //String objectStr="{\"common\":\"999\",\"student\":\"[{\"name\":\"yanghua\",\"age\":\"24\",\"address\":\"55555\"}]\"}";
        String objectStr="{\"common\":\"999\",\"student\":\"[{\\\"name\\\":\\\"JSON\\\",\\\"age\\\":\\\"24\\\",\\\"address\\\":\\\"北京市西城区\\\"},{\\\"name\\\":\\\"JSON222\\\",\\\"age\\\":\\\"242\\\",\\\"address\\\":\\\"北京市西城区2\\\"}]\"}";


        //1、使用JSONObject
        JSONObject jsonObject= JSONObject.fromObject(objectStr);
        Object student = jsonObject.get("student");

        System.out.println(student);
        //2、使用JSONArray
        JSONArray jsonArray=JSONArray.fromObject(student);
        //获得jsonArray的第一个元素
        for (int i = 0; i <jsonArray.size() ; i++) {
            Object o=jsonArray.get(i);
            System.out.println(jsonArray.size());
            JSONObject jsonObject2=JSONObject.fromObject(o);
            Student stu2=(Student)JSONObject.toBean(jsonObject2, Student.class);

            System.out.println("stu2:"+stu2);
        }


    }
    private String name;
    private String age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}
